import util from 'util'
const system = {
    // 初始化 vuex
    state: {
      theme:'',
      collapsed:false,   //菜单是否关闭  展示缩略图
      navState:true,
      menuList:[],      //浏览过的路由列表,
      activeMenu:{},     //当前激活的左侧菜单
      alarmShow: false,
      userInfo: {},
      fullState:false
    },
    mutations: {
        setFullState(state, info){
            state.fullState =info;
        },
        setUserInfo(state, info) {
            state.userInfo = info;
        },
        setAlarmShow(state, info) {
            state.alarmShow = info;
        },
        setNavState:function(state,info){
            state.navState=info;
        },
        setTheme:function(state,info){
            state.theme=info;
        },
        setCollapsed:function(state,info){
            state.collapsed=info;
        },
        //新增一个tab 页
        addMenuList:function(state,info){
            for(var i =0;i<state.menuList.length;i++){
                if(state.menuList[i].menuId===info.menuId){
                    break;
                }
                if(i==state.menuList.length-1){
                    state.menuList.push(info);
                }
            }
            state.activeMenu=info;
            if(state.menuList==null ||state.menuList.length==0){
                state.menuList.push(info);
            }
            util.util.sysnLocastore(state);
        },
        //刷新的时候  缓存最后一个浏览页面 加载最后一个浏览页面的tab页和导航页
        setMenuAndActive(state,active){
            if(active!=null){
                state.activeMenu=active;
                state.menuList.push(active);
            }
        },
        setActiveMenu(state,info){
            state.activeMenu =info;
        },

        //单机 关闭一个tab标签
        closeTab(state,info){
            state.menuList.splice(info.index,1);
            if(info.item.menuId==state.activeMenu.menuId){
                if(state.menuList.length>0){
                    state.activeMenu=state.menuList[state.menuList.length-1];
                }
            }
            if(state.menuList.length==0){
                state.activeMenu={};
            }
        }
    },
    actions: {

    },
    getters: {
        collapsed: state=>state.collapsed,
        menuList: state=>state.menuList,
        activeMenu: state=>state.activeMenu,
        theme: state=>state.theme,
        navState:state=>state.navState,
        alarmShow: state=>state.alarmShow,
        userInfo: state=>state.userInfo,
        fullState: state=>state.fullState
    }
  }

  export default system;
